var jsonobj1=""
var  resultiowk={};
var newdata=""
var oldstart=""
var inputmm=""
var inputid=""
var inputcode=""
var inputmsg=""
var modifyPriceWays=""
var customerTypes=""
//合同信息详情
contractxixi()
function contractxixi() {
    $.ajax({
        /*root.inter.findContractInfoByPage*/
        url: root.inter.findContractInfoByPage,
        cache: false,  //禁用缓存
        type: "POST",
        async:false,
        dataType:'json',
        data: {
            "pageNum":1,
            "pageSize":10,
            "contractNum" :getQueryString('contractNum'),
            "customerCode":getQueryString('customerCode'),

        },
        success: function (data) {
            if(data.data.result&& data.data.result.length>0){
                $.each(data.data.result,function(k,v){
                    oldstart=v
                    customerTypes= v.customerType
                    customerIdss=v.customerId
                    customercodess=v.customerCode
                    sessionStorage.setItem("customerId",customerIdss);
                    sessionStorage.setItem("customerCodes",customercodess);
                    sessionStorage.setItem("contractNusm",v.contractNum);
                    console.log(v)
                    $('#contractNum').html(v.contractNum)
                    $('#oldSysContractNum').html(v.oldSysContractNum)
                    $('#contractType').html(v.contractType)
                    $('#customerBelongGroupName').html(v.customerBelongGroupName)
                    $('#oldContractState').html(v.oldContractState)
                    $('#customerName').html(v.customerName)
                    $('#conStartDate').html(v.conStartDate)
                    $('#conEndDate').html(v.conEndDate)
                    $('#ftotalmount').html(v.ftotalmount)
                    $('#credit').html(v.credit)
                    $('#tickQuota').html(v.tickQuota)
                    $('#balanceWay').html(v.balanceWay)
                    $('#fcontractcontent').html(v.fcontractcontent)
                    if(v.settleCycleFirst!=""||v.settleCycleSecond!=""||v.settleCycleThird!=""){
                        if(v.settleCycleFirst==1){
                            $('#settlecyclesecond').html('当月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==2){
                            $('#settlecyclesecond').html('次月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==3){
                            $('#settlecyclesecond').html('第三个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==4){
                            $('#settlecyclesecond').html('第四个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==5){
                            $('#settlecyclesecond').html('第五个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==6){
                            $('#settlecyclesecond').html('第六个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }


                    }else {
                        $('#settlecyclesecond').html("")
                    }
                    $('#checkoutCycle').html(v.checkoutCycle)

                })
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//修改合同状态
var index=0;
function updtastart(el) {
    var startntr=""
    if(oldstart.oldContractState=='启用'){
        startntr="关闭"
    }else {
        startntr="启用"
    }
    var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >您确定要'+startntr+'合同状态吗？</span>', {title:'提示',btn: ['确定', '取消']}, function(index){
        var code= $(el).attr("id")
        fish5(code)

        layer.close(curInd);
    },function(){
        layer.close(curInd);

    });
}
function fish5(code){
    var startcontr=""
    if(oldstart.oldContractState=='启用'){
        startcontr="关闭"
    }else {
        startcontr="启用"
    }
    $.ajax({
        /*root.inter.updateFictitiousContractStatus*/
        url:root.inter.updateFictitiousContractStatus,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            customerCode:getQueryString('customerCode'),
            status:startcontr,
            contractNum:getQueryString('contractNum')
        },
        success: function (data) {
            if(data.sub_code==0){
                $.Huimodalalert('修改成功！',2000);
                contractxixi()
            }else {
                $.Huimodalalert(data.sub_msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })

    layer.close(index);
}

//查询
seahsdfs();
function seahsdfs() {
    $.ajax({
        url:root.inter.findCategoryDiscountForPage,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            pageNum:1,
            pageSize:20,
           /* getQueryString('id')*/
            /*sessionStorage.getItem("id")*/
            "contractNum" :getQueryString('contractNum'),
            "customerCode":getQueryString('customerCode'),
            "modifyPriceWay":""

        },
        success: function (result) {
            detaiist(result);
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.inter.findCategoryDiscountForPage,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        async:false,
                        data: {
                            pageNum:api.getCurrent(),
                            pageSize:20,
                            "contractNum" :getQueryString('contractNum'),
                            "customerCode":getQueryString('customerCode'),
                            "modifyPriceWay":""

                        },
                        success: function (result) {
                            detaiist(result);
                            $("#spu_all").attr("checked", false);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
/*表格渲染*/
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];

function detaiist(data) {
    newdata=data
    dataSource.splice(0, dataSource.length);//清空数组
        if (data.data.result!="") {
            $.each(data.data.result, function (i, field) {
                var rowData = new Array();
                rowData.push(field.oneCategoryName);
                rowData.push(field.twoCategoryName);
                rowData.push(field.categoryName);
                rowData.push(field.brand);
                rowData.push(field.spuCode);
                rowData.push(field.productName);
                rowData.push(field.skuCode);
                rowData.push(field.saleAttriValue);
                rowData.push(field.modifyPriceWay);
                rowData.push(field.categoryDiscount);
                rowData.push(field.contractCategoryDiscountId);
                dataSource.push(rowData);
            });
        }
    initDataTable(dataSource);

    function initDataTable(dataSource) {
        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "order": [[ 1, "desc" ]],
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": [5, 10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = '<span style="text-align: left;"><td><input class="spuId" type="checkbox" name="spuId" value = "' + row[10] + '">' + row[0] + '</td></span>';
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = '';
                        if (row[8] == 10 && row[6] == "") {
                            var val = '<span style="display: inline-block;width: 210px;"><td ><select class="select radius w-100 va-m" style="height:26px" onchange="jine(this)"><option value="10" >折扣率</option></select></td><td><input style="width: 50px;" type="text" value="'+(row[9]*100).toFixed(0)+'"><span style="display: inline-block;">%</span></td>&nbsp;<td><a class="powerButton 244" onclick="Cloes(\''+row[8]+'\',\''+row[10]+'\',\''+row[6]+'\',this)">修改</a></td></span>';
                        }else if (row[8] == 10 && row[6] != "") {
                            var val = '<span style="display: inline-block;width: 210px;"><td ><select class="select radius w-100 va-m" style="height:26px" onchange="jine(this)"><option value="10">折扣率</option><option value="20" >金额上调</option><option value="30">金额下调</option></select></td><td><input style="width: 50px;" type="text" value="'+(row[9]*100).toFixed(0)+'"><span style="display: inline-block;">%</span></td>&nbsp;<td><a class="powerButton 244" onclick="Cloes(\''+row[8]+'\',\''+row[10]+'\',\''+row[6]+'\',this)">修改</a></td></span>';
                        } else if (row[8] == 20) {
                            var val = '<span style="display: inline-block;width: 210px;"><td><select class="select radius w-100 va-m" style="height:26px" onchange="jine(this)"><option value="10">折扣率</option><option value="20" selected>金额上调</option><option value="30">金额下调</option></select></td><td><input style="width: 50px;" type="text" value="'+row[9]+'"><span  style="display: none">%</span></td><td>&nbsp;<a class="powerButton 244" onclick="Cloes(\''+row[8]+'\',\''+row[10]+'\',\''+row[6]+'\',this)">修改</a></td></span>';
                        } else if (row[8] == 30) {
                            var val = '<span style="display: inline-block;width: 210px;"><td><select class="select radius w-100 va-m" style="height:26px" onchange="jine(this)"><option value="10">折扣率</option><option value="20">金额上调</option><option value="30" selected>金额下调</option></select></td><td><input style="width: 50px;" type="text" value="'+row[9]+'"><span  style="display: none">%</span></td><td>&nbsp;<a class="powerButton 244" onclick="Cloes(\''+row[8]+'\',\''+row[10]+'\',\''+row[6]+'\',this)">修改</a></td></span>';
                        }
                        return val;
                    },
                    "targets": 8
                },
                {
                    "render": function (data, type, row) {
                        var val = '<span class="powerButton 244"><a onclick="detaildelete(\''+row[10]+'\')">删除</a></span>';
                        return val;
                    },
                    "targets": 9
                }
            ],
            "fnInitComplete": function(oSettings, json) {
                setBtnDis(0, $("#productManage"));
                $("#datatable").on("change", '.spuId', function() {
                    var num = $(".shun").find("input[type=checkbox]:checked").length;
                    setBtnDis(num, $("#productManage"));
                });

            }
        });
    };
    //权限控制函数
    power()
}
//设置金额上下调金额默认为0
//设置金额上下调金额默认为0
function jine(el) {
    if(newdata.data.result.length>0){
        $.each(newdata.data.result,function(k,v){
            if($(el).parent().find('select').val()==20){
                $(el).parent().find('input').val(0)
                var spanEl = el.nextSibling.nextSibling;
                $(spanEl).css({
                    display: "none"
                });


            } else if($(el).parent().find('select').val()==30){
                $(el).parent().find('input').val(0)
                var spanElq = el.nextSibling.nextSibling;
                $(spanElq).css({
                    display: "none"
                });

            }else if($(el).parent().find('select').val()==10){
                $(el).parent().find('input').val(100)
                var spanEldf = el.nextSibling.nextSibling;
                $(spanEldf).css({
                    display: "inline-block"
                });


            }

        });
    }


}
var crmCustomerIdOnearry =[];//存放多选时的crmCustomerid
var crmCustomerIdsall=[]//存放id
//一级
function goodslistCategory() {
    $.ajax({
        url: root.inter.categoryByParams,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,//优先运行
        contentType: "application/json",
        data: JSON.stringify({
            "categoryLevel":1,
            "categoryLevels": [],
            "categoryName":$("#class1").val(),
        }),
        success: function (data) {
            var classStr = "";
            var str = "";
            var str2 = "";
            var str3 = "";
            if(data.errorCode == "0") {
                if(data.data == null || data.data == "") {
                    classStr = "<li>无数据</li>"
                    $("#classUl1").html(classStr);
                } else {
                    //category_id
                    for (var k = 0; k < data.data.length; k++) {
                        str += data.data[k].category_id+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str.length > 0) {
                        str = str.substr(0, str.length - 1);
                    }
                    //category_name
                    for (var j = 0; j < data.data.length; j++) {
                        str2 += data.data[j].category_name+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str2.length > 0) {
                        str2 = str2.substr(0, str2.length - 1);
                    }
                    //parent_cate_id
                    for (var g = 0; g < data.data.length; g++) {
                        str3 += data.data[g].parent_cate_id+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str3.length > 0) {
                        str3 = str3.substr(0, str3.length - 1);
                    }
                        console.log(crmCustomerIdOnearry)
                        classStr += '<li class=""><input type="checkbox" id="checkboxalls" crmCustomerId="'+str+'" crmCustomername="'+str2+'" crmCustomerparentid="'+str3+'" onchange="goodslistCategory2()"><span class="checkboxall">全选/反选</span></li>';
                    if(crmCustomerIdOnearry!=""){
                        $.each(data.data,function(k,n){
                                if(Number(crmCustomerIdOnearry[k].categoryId)==n.category_id){
                                    classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' +n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyipt" onchange="goodslistCategory2()" checked><span>' + n.category_name + '</span></li>'

                                }else {
                                    classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' + n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyipt" onchange="goodslistCategory2()"><span>' + n.category_name + '</span></li>'

                                }
                            });

                    }else {
                        for(var i = 0; i < data.data.length; i++) {
                            classStr +='<li class="lidata" crmCustomerId="'+data.data[i].category_id+'" crmCustomername="'+data.data[i].category_name+'"  crmCustomerparentid="'+data.data[i].parent_cate_id+'"><input type="checkbox" onchange="goodslistCategory2()" class="evetyipt"><span>'+data.data[i].category_name+'</span></li>'

                        }
                    }
                    $(".ulbox").html(classStr);
                    //全选按钮展示
                    if(Number(crmCustomerIdOnearry.length)==Number(data.data.length)){
                        $(".checkboxall").prev().prop('checked',true);
                    }else {
                        $(".checkboxall").prev().prop('checked',false);
                    }
                }
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });

}

//分类全选反选
var crmCustomerIdOne={};
$(".ulbox").css('display','none');
/*点击 项目 显示下拉 选项,其中全选全不选，要做传值的处理*/
$(".dataval,.icon_arrow").on('click',function (e) {
    $(this).parent().children(".icon_arrow").toggleClass("icon_arrow_down");
    if($('.ulbox').css("display") == "none"){
        $('.ulbox').show();
        crmCustomerIdsall=[]
    }else{
        $(".ulbox").hide();
    }
    e.stopPropagation();
});

var checkednum=0;
//当点击下拉数据时 回显在input里面
$(".ulbox").on('click','input.evetyipt',function (e) {
    e.stopPropagation();
    if($(this).prop('checked')){
        $(this).prop('checked',true);//选中
        checkednum ++;
        crmCustomerIdOne={
            "categoryId":$(this).parent().attr('crmCustomerId'),
            "categoryName":$(this).parent().attr('crmCustomername'),
            "parentCateId":$(this).parent().attr('crmCustomerparentid'),
        }
        crmCustomerIdOnearry.push(crmCustomerIdOne);
        console.log(crmCustomerIdOnearry)
        crmCustomerIdsall=[]
        if($(".ulbox").find('input.evetyipt').length == checkednum){
            $(".checkboxall").prev().prop('checked',true);
        }
        //全选反选时会用
        if (checkednum==0) {
            $(".checkboxall").prev().prop('checked',true);

        }
    }else{
        checkednum --;
        $(this).prop('checked',false);
        var checkfalsehtml =  $(this).next().html();
        crmCustomerIdsall.push($(this).parent().attr('crmCustomerId'))
        console.log(crmCustomerIdsall)
        for (var m=0;m<crmCustomerIdsall.length;m++) {
            for (var i=0;i<crmCustomerIdOnearry.length;i++){
                if(crmCustomerIdOnearry[i].categoryId == crmCustomerIdsall[m]){
                    crmCustomerIdOnearry.splice(i,1);
                    break;
                }
            }
        }
    console.log(crmCustomerIdOnearry)
        var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
        $.each(iptspandata,function (i,item) {
            if($(item).html() == checkfalsehtml){
                $(item).html('');
                $(item).remove();
            }
        });
        if($(".ulbox").find('input.evetyipt').length != checkednum){
            $(".checkboxall").prev().prop('checked',false);
        }
    }
});
var crmCustomerIdboxall={}
/*点击全选 联动 传值*/
$(".ulbox").on('click','#checkboxalls',function (e) {
    crmCustomerIdOnearry=[]
    e.stopPropagation();
    if($(this).prop('checked')){//全选
        $(this).prop('checked',true);
        $(".ulbox").find('li').find('input').prop('checked',true);
        for (var i=0;i<$(this).attr('crmCustomerId').split(",").length;i++){
            crmCustomerIdboxall={
                "categoryId":$(this).attr('crmCustomerId').split(",")[i],
                "categoryName":$(this).attr('crmCustomername').split(",")[i],
                "parentCateId":$(this).attr('crmCustomerparentid').split(",")[i],
            }
            crmCustomerIdOnearry.push(crmCustomerIdboxall)
        }


    }else{//全不选
        $(this).prop('checked',false);
        $(".ulbox").find('li').find('input').prop('checked',false);
        crmCustomerIdOnearry=[];
    }
})
$("#class1").focus(function() {
    goodslistCategory(1);
});

//二级
var crmCustomerIdTwoarry =[];//存放多选时的crmCustomerid
var crmCustomerIdsalltwo=[]//存放取消选中的crmCustomerid

function goodslistCategory2() {
    var TwocategoryLevels=[]
    for (var x=0;x<crmCustomerIdOnearry.length;x++) {
        TwocategoryLevels.push(crmCustomerIdOnearry[x].categoryId)
    }
    $.ajax({
        url: root.inter.categoryByParams,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,//优先运行
        contentType: "application/json",
        data: JSON.stringify({
            "categoryLevels":TwocategoryLevels,
            "categoryName":$("#class2").val(),
        }),
        success: function (data) {
            var classStr = "";
            var str = "";
            var str2 = "";
            var str3 = "";
            if(data.errorCode == "0") {
                if(data.data == null || data.data == "") {
                    classStr = "<li>无数据</li>"
                    $("#classUl2").html(classStr);
                } else {
                    //category_id
                    for (var k = 0; k < data.data.length; k++) {
                        str += data.data[k].category_id+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str.length > 0) {
                        str = str.substr(0, str.length - 1);
                    }
                    //category_name
                    for (var j = 0; j < data.data.length; j++) {
                        str2 += data.data[j].category_name+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str2.length > 0) {
                        str2 = str2.substr(0, str2.length - 1);
                    }
                    //parent_cate_id
                    for (var g = 0; g < data.data.length; g++) {
                        str3 += data.data[g].parent_cate_id+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str3.length > 0) {
                        str3 = str3.substr(0, str3.length - 1);
                    }
                    classStr += '<li class=""><input type="checkbox" id="checkboxallsTwo" crmCustomerId="'+str+'" crmCustomername="'+str2+'" crmCustomerparentid="'+str3+'" onchange="goodslistCategory3()"><span class="checkboxallTwo">全选/反选</span></li>';
                    if(crmCustomerIdTwoarry!=""){
                        console.log(crmCustomerIdTwoarry)
                      /*  $.each(data.data,function(k,n){

                            if(crmCustomerIdTwoarry[k]!=undefined){
                                if(Number(crmCustomerIdTwoarry[k].categoryId)==n.category_id){

                                    classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' +n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" checked onchange="goodslistCategory3()"><span>' + n.category_name + '</span></li>'

                                }
                            } else {
                                classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' + n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" onchange="goodslistCategory3()"><span>' + n.category_name + '</span></li>'

                            }
                        });*/
                        var crmCustomerIdTwoarryarr={}
                        for (let device of crmCustomerIdTwoarry) {
                            crmCustomerIdTwoarryarr[device.categoryId]=[]
                        }

                        for (let n of data.data) {
                            if(crmCustomerIdTwoarryarr.hasOwnProperty(n.category_id)){
                                classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' +n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" checked onchange="goodslistCategory3()"><span>' + n.category_name + '</span></li>'

                            }else {
                                classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' + n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" onchange="goodslistCategory3()"><span>' + n.category_name + '</span></li>'

                            }
                        }

                    }else {
                        for(var i = 0; i < data.data.length; i++) {
                            classStr +='<li class="lidata" crmCustomerId="'+data.data[i].category_id+'" crmCustomername="'+data.data[i].category_name+'"  crmCustomerparentid="'+data.data[i].parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" onchange="goodslistCategory3()"><span>'+data.data[i].category_name+'</span></li>'

                        }
                    }
                    $(".ulbox2").html(classStr);
                    //全选按钮展示
                    if(Number(crmCustomerIdTwoarry.length)==Number(data.data.length)){
                        $(".checkboxallTwo").prev().prop('checked',true);
                    }else {
                        $(".checkboxallTwo").prev().prop('checked',false);
                    }
                }
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });

}

//分类全选反选
var crmCustomerIdTwo={};
$(".ulbox2").css('display','none');
/*点击 项目 显示下拉 选项,其中全选全不选，要做传值的处理*/
$(".dataval2").on('click',function (e) {
    if($('.ulbox2').css("display") == "none"){
        $('.ulbox2').show();
        crmCustomerIdsalltwo=[]
    }else{
        $(".ulbox2").hide();
    }
    e.stopPropagation();
});

var checkednumTwo=0;
//当点击下拉数据时 回显在input里面
$(".ulbox2").on('click','input.evetyiptTwo',function (e) {
    e.stopPropagation();
    if($(this).prop('checked')){
        $(this).prop('checked',true);//选中
        checkednumTwo ++;
        crmCustomerIdTwo={
            "categoryId":$(this).parent().attr('crmCustomerId'),
            "categoryName":$(this).parent().attr('crmCustomername'),
            "parentCateId":$(this).parent().attr('crmCustomerparentid'),
        }
        crmCustomerIdTwoarry.push(crmCustomerIdTwo);
        crmCustomerIdsalltwo=[]
        if($(".ulbox2").find('input.evetyiptTwo').length == checkednumTwo){
            $(".checkboxallTwo").prev().prop('checked',true);
        }
        //全选反选时会用
        if (checkednumTwo==0) {
            $(".checkboxallTwo").prev().prop('checked',true);

        }
    }else{
        checkednumTwo --;
        $(this).prop('checked',false);
        var checkfalsehtml =  $(this).next().html();
        crmCustomerIdsalltwo.push($(this).parent().attr('crmCustomerId'))
        for (var m=0;m<crmCustomerIdsalltwo.length;m++) {
            for (var i=0;i<crmCustomerIdTwoarry.length;i++){
                if(crmCustomerIdTwoarry[i].categoryId == crmCustomerIdsalltwo[m]){
                    crmCustomerIdTwoarry.splice(i,1);
                }
            }}

        var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
        $.each(iptspandata,function (i,item) {
            if($(item).html() == checkfalsehtml){
                $(item).html('');
                $(item).remove();
            }
        });
        if($(".ulbox2").find('input.evetyiptTwo').length != checkednumTwo){
            $(".checkboxallTwo").prev().prop('checked',false);
        }
    }
});
var crmCustomerIdboxallTwo={}
/*点击全选 联动 传值*/
$(".ulbox2").on('click','#checkboxallsTwo',function (e) {
    crmCustomerIdTwoarry=[]
    e.stopPropagation();
    if($(this).prop('checked')){//全选
        $(this).prop('checked',true);
        $(".ulbox2").find('li').find('input').prop('checked',true);
        for (var i=0;i<$(this).attr('crmCustomerId').split(",").length;i++){
            crmCustomerIdboxallTwo={
                "categoryId":$(this).attr('crmCustomerId').split(",")[i],
                "categoryName":$(this).attr('crmCustomername').split(",")[i],
                "parentCateId":$(this).attr('crmCustomerparentid').split(",")[i],
            }
            crmCustomerIdTwoarry.push(crmCustomerIdboxallTwo)
        }


    }else{//全不选
        $(this).prop('checked',false);
        $(".ulbox2").find('li').find('input').prop('checked',false);
        crmCustomerIdTwoarry=[];
    }
})
$("#class2").focus(function() {
    goodslistCategory2();
});



//三级
var crmCustomerIdThreearry =[];//存放多选时的crmCustomerid
var crmCustomerIdsallThree=[]//存放取消选中的crmCustomerid

function goodslistCategory3() {
    var ThreecategoryLevels=[]
    for (var x=0;x<crmCustomerIdTwoarry.length;x++) {
        ThreecategoryLevels.push(crmCustomerIdTwoarry[x].categoryId)
    }
    $.ajax({
        url: root.inter.categoryByParams,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,//优先运行
        contentType: "application/json",
        data: JSON.stringify({
            "categoryLevels":ThreecategoryLevels,
            "categoryName":$("#class3").val(),
        }),
        success: function (data) {
            var classStr = "";
            var str = "";
            var str2 = "";
            var str3 = "";
            if(data.errorCode == "0") {
                if(data.data == null || data.data == "") {
                    classStr = "<li>无数据</li>"
                    $("#classUl3").html(classStr);
                } else {
                    //category_id
                    for (var k = 0; k < data.data.length; k++) {
                        str += data.data[k].category_id+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str.length > 0) {
                        str = str.substr(0, str.length - 1);
                    }
                    //category_name
                    for (var j = 0; j < data.data.length; j++) {
                        str2 += data.data[j].category_name+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str2.length > 0) {
                        str2 = str2.substr(0, str2.length - 1);
                    }
                    //parent_cate_id
                    for (var g = 0; g < data.data.length; g++) {
                        str3 += data.data[g].parent_cate_id+ ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (str3.length > 0) {
                        str3 = str3.substr(0, str3.length - 1);
                    }
                    classStr += '<li class=""><input type="checkbox" id="checkboxallsThree" crmCustomerId="'+str+'" crmCustomername="'+str2+'" crmCustomerparentid="'+str3+'"><span class="checkboxallThree">全选/反选</span></li>';
                    if(crmCustomerIdThreearry!=""){
                        /*$.each(data.data,function(k,n){
                            if(crmCustomerIdThreearry[k]!=undefined){
                                if(Number(crmCustomerIdThreearry[k].categoryId)==n.category_id){
                                    classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' +n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" checked><span>' + n.category_name + '</span></li>'

                                }
                            } else {
                                classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' + n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo"><span>' + n.category_name + '</span></li>'

                            }
                        });*/
                        var crmCustomerIdThreearryarr={}
                        for (let device of crmCustomerIdThreearry) {
                            crmCustomerIdThreearryarr[device.categoryId]=[]
                        }

                        for (let n of data.data) {
                            if(crmCustomerIdThreearryarr.hasOwnProperty(n.category_id)){
                                classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' +n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo" checked><span>' + n.category_name + '</span></li>'

                            }else {
                                classStr += '<li class="lidata" crmCustomerId="' + n.category_id + '" crmCustomername="' + n.category_name + '"  crmCustomerparentid="'+n.parent_cate_id+'"><input type="checkbox" class="evetyiptTwo"><span>' + n.category_name + '</span></li>'

                            }
                        }

                    }else {
                        for(var i = 0; i < data.data.length; i++) {
                            classStr +='<li class="lidata" crmCustomerId="'+data.data[i].category_id+'" crmCustomername="'+data.data[i].category_name+'"  crmCustomerparentid="'+data.data[i].parent_cate_id+'"><input type="checkbox" class="evetyiptTwo"><span>'+data.data[i].category_name+'</span></li>'

                        }
                    }
                    $(".ulbox3").html(classStr);
                    //全选按钮展示
                    if(Number(crmCustomerIdThreearry.length)==Number(data.data.length)){
                        $(".checkboxallThree").prev().prop('checked',true);
                    }else {
                        $(".checkboxallThree").prev().prop('checked',false);
                    }
                }
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });

}

//分类全选反选
var crmCustomerIdThree={};
$(".ulbox3").css('display','none');
/*点击 项目 显示下拉 选项,其中全选全不选，要做传值的处理*/
$(".dataval3").on('click',function (e) {
    if($('.ulbox3').css("display") == "none"){
        $('.ulbox3').show();
        crmCustomerIdsallThree=[]
    }else{
        $(".ulbox3").hide();
    }
    e.stopPropagation();
});

var checkednumThree=0;
//当点击下拉数据时 回显在input里面
$(".ulbox3").on('click','input.evetyiptTwo',function (e) {
    e.stopPropagation();
    if($(this).prop('checked')){
        $(this).prop('checked',true);//选中
        checkednumThree ++;
        crmCustomerIdThree={
            "categoryId":$(this).parent().attr('crmCustomerId'),
            "categoryName":$(this).parent().attr('crmCustomername'),
            "parentCateId":$(this).parent().attr('crmCustomerparentid'),
        }
        crmCustomerIdThreearry.push(crmCustomerIdThree);
        crmCustomerIdsallThree=[]
        if($(".ulbox3").find('input.evetyiptTwo').length == checkednumThree){
            $(".checkboxallThree").prev().prop('checked',true);
        }
        //全选反选时会用
        if (checkednumThree==0) {
            $(".checkboxallThree").prev().prop('checked',true);

        }
    }else{
        checkednumThree --;
        $(this).prop('checked',false);
        var checkfalsehtml =  $(this).next().html();
        crmCustomerIdsallThree.push($(this).parent().attr('crmCustomerId'))
        for (var m=0;m<crmCustomerIdsallThree.length;m++) {
            for (var i=0;i<crmCustomerIdThreearry.length;i++){
                if(crmCustomerIdThreearry[i].categoryId == crmCustomerIdsallThree[m]){
                    crmCustomerIdThreearry.splice(i,1);
                }
            }}

        var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
        $.each(iptspandata,function (i,item) {
            if($(item).html() == checkfalsehtml){
                $(item).html('');
                $(item).remove();
            }
        });
        if($(".ulbox3").find('input.evetyiptTwo').length != checkednumThree){
            $(".checkboxallThree").prev().prop('checked',false);
        }
    }
});
var crmCustomerIdboxallThree={}
/*点击全选 联动 传值*/
$(".ulbox3").on('click','#checkboxallsThree',function (e) {
    crmCustomerIdThreearry=[]
    e.stopPropagation();
    if($(this).prop('checked')){//全选
        $(this).prop('checked',true);
        $(".ulbox3").find('li').find('input').prop('checked',true);
        for (var i=0;i<$(this).attr('crmCustomerId').split(",").length;i++){
            crmCustomerIdboxallThree={
                "categoryId":$(this).attr('crmCustomerId').split(",")[i],
                "categoryName":$(this).attr('crmCustomername').split(",")[i],
                "parentCateId":$(this).attr('crmCustomerparentid').split(",")[i],
            }
            crmCustomerIdThreearry.push(crmCustomerIdboxallThree)
        }


    }else{//全不选
        $(this).prop('checked',false);
        $(".ulbox3").find('li').find('input').prop('checked',false);
        crmCustomerIdThreearry=[];
    }
})
$("#class3").focus(function() {
    goodslistCategory3();
});


//点击空白处事件
$(document).on('click',function(){
    $(".ulbox").css('display','none');
    $(".ulbox2").css('display','none');
    $(".ulbox3").css('display','none');
})

/*品牌选择*/
function myfFunction(){
     brandName = "";
     brandId = "";
    $.ajax({
        url: root.goodsInter.goods_getListBrand,
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            brandName: $("#username").val().trim()
        },
        success: function (data) {
            console.log(data)
            var jsonObj =data.ListBrand;
            if(jsonObj==""){
                $("#tudfan").html("<li>无数据</li> ");
            }else {
                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    jsonobj1=jsonObj[i].brandId
                    brandIds=jsonObj[i].brandId
                    optionstring += "<li onclick='addCodeFun("+ jsonObj[i].brandId+ ",\""+jsonObj[i].brandName+ "\")'>"+jsonObj[i].brandName+ "</li>";
                }
                $("#tudfan").html(optionstring);
            }
        }
    });
}
//品牌获取光标
$("#username").focus(function () {
    $("#tudfan").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tudfan").length == 0 && $(e.target).closest("#username").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tudfan").hide()
    }
})
var brandName = "";
var brandId = "";
function addCodeFun(id,brand_name) {
    $("#tudfan").hide();
    $("#username").val(brand_name)
    brandName = brand_name;
    brandId = id;
}
function brand_sure() {
    sessionStorage.setItem("brand_name",brandName);
    sessionStorage.setItem("brand_id",brandId);
    $("#selectInp").css({
        display:"none"
    });
    addBrandName();
}
//渲染品牌名称
function addBrandName() {
    if(sessionStorage.getItem("brand_name")){
        $("#brandName").html(sessionStorage.getItem("brand_name"));
        $("#brandId").html(sessionStorage.getItem("brand_id"));
    }
}
//渲染属性名称
function addAttrName() {
    console.log(sessionStorage.getItem("attrObjCanch")+"##########");
    if(sessionStorage.getItem("attrObjCanch")){
        var attrObjCanch = JSON.parse(sessionStorage.getItem("attrObjCanch"));
        for(var i=0;i<attrObjCanch.length;i++){
            var attrValStr="";
            var attrIdsStr="";
            if(attrObjCanch[i].value.length != 0){
                for(var j=0;j<attrObjCanch[i].value.length;j++){
                    attrValStr += attrObjCanch[i].value[j].attri_value+";";
                    attrIdsStr +=attrObjCanch[i].value[j].attri_value_id+";";
                }
            }
            $("#appendAttr").remove();
            $("#attrTable").append('<tr id = "appendAttr"><th class="col-6-1 text-c">'+attrObjCanch[i].attribute_name+'</th><td><span>'+attrValStr+'</span><a onclick="addAttr('+attrObjCanch[i].attribute_id+",'"+attrIdsStr+"'"+')">添加</a></td></tr>')
        }
    }
}
function stoprop() {
    /*批量上架全选框阻止冒泡*/
    var timer = setTimeout(function() {
        var num = $("#datatable").find("tbody").find("input[type=checkbox]:checked").length;
        setBtnDis(num, $("#productManage"));
        clearTimeout(timer);
    }, 200)

    window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
function setBtnDis(num, pnode) { //如果选中项为空时，置灰相关按钮
    if(num <= 0) {
        pnode.find(".goods_edit").attr("disabled", "disabled").addClass("dis_btn");
    } else {
        pnode.find(".goods_edit").removeAttr("disabled").removeClass("dis_btn");
    }
}

//添加
function detailadd() {
    var brandIds=""
    var brandIdname=""
    if($("#username").val()==""){
        brandIds=""
        brandIdname=""
            brandIdname=""
    }else {
        if(brandId!=""||brandName!=""){
            brandIds=brandId/*jsonobj1*/
            brandIdname=brandName
        }else {
            $.Huimodalalert('品牌不存在！',2000);
            return false;
        }
    }

    $.ajax({
        url:root.inter.saveCategoryDiscounts,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "oneCategoryList":crmCustomerIdOnearry,
            "twoCategoryList":crmCustomerIdTwoarry,
            "threeCategoryList":crmCustomerIdThreearry,
            "brand": brandIdname,
            "brandId":brandIds,
            "modifyPriceWay": '10',
            "saleAttriValue": "",
            "categoryDiscount": '1',
            "flag": '10',
            "customerId":sessionStorage.getItem("customerId"),
            "customerCode":getQueryString('customerCode'),
            "contractNum": getQueryString('contractNum'),
            "createName": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            "productCode":"",
            "spuCode": "",
            "productName": "",
            "skuCode": "",
            "imgUrl": "",
            "unitName": "",//计量单位
            "areaName": "", //商品区域名
            "prices":[],
        }),
        success: function (data) {
            if (data.errorCode==1){
                $.Huimodalalert(data.msg,2000);
            }else {
                crmCustomerIdOnearry=[]
                crmCustomerIdTwoarry=[]
                crmCustomerIdThreearry=[]
                seahsdfs();
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
var customertype=""
//修改
function Cloes(modifyPriceWay,id,skucode,el) {
    console.log(customerTypes)
    if (customerTypes=="商店"){
        console.log("1111")
        customertype=10
    }else {
        customertype=20
    }
    inputmm=$(el).parent().find('input').val()
    inputid=id
    inputcode=skucode
    modifyPriceWays=$(el).parent().find('select').val()
    $.ajax({
        url:root.inter.updateBatchCategoryDiscount,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            modifyPriceWay:$(el).parent().find('select').val(),
            categoryDiscount:$(el).parent().find('input').val(),
            contractCategoryDiscountId :id,
            skuCode:skucode,
            customerType:customertype

        },
        success: function (data) {
            seahsdfs();
            if(data.errorCode==0){
                if(data.sub_code==2){
                    inputmsg=data.sub_msg
                    updamm(1);
                }else if(data.sub_code==3){
                    $.Huimodalalert(data.sub_msg,2000);
                }else {
                    $.Huimodalalert('修改成功！',2000);
                }
            }else {
                $.Huimodalalert(data.msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
//修改密码
var index=0;
function updamm(val) {
    var cu = layer.confirm('<span>'+inputmsg+",确认修改请输入密码"+'</span><input class="input-text radius" placeholder="请输入密码" type="password" style="padding-left: 10px;" id="remarksr">', {title:'提示',btn: ['确认', '取消']}, function(index){
        fini3(val)
        layer.close(cu);
    },function(){
        layer.close(cu);

    });
}
//第二个
function fini3(val){
    var remarksr = $("#remarksr").val();
    console.log(remarksr)

    $.ajax({
        url:root.orderInter.checkPriceRevisionPwd,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            password:$("#remarksr").val().trim()
        },
        success: function (data) {
            if(data.data==10){
                if (customerTypes=="商店"){
                    customertype=10
                }else {
                    customertype=20
                }
                var contractCategoryDiscountIdarr=[]
                if(val==1){
                    /*单个修改*/
                    contractCategoryDiscountIdarr.push(inputid)
                }else {
                    /*批量修改*/
                    var spuIdArr=document.getElementsByName('spuId');
                    var str=""
                    for(var i=0; i < spuIdArr.length;i++){
                        if(spuIdArr[i].checked==true){
                            str+= spuIdArr[i].value+','
                        }
                    }
                    str = str.substring(0, str.length - 1);
                    contractCategoryDiscountIdarr = [];
                    if (str.indexOf(",") != -1) {
                        var split = str.split(",");
                        for (var i = 0; i < split.length; i++) {
                            contractCategoryDiscountIdarr.push(Number(split[i]));
                        }
                    } else {
                        contractCategoryDiscountIdarr.push(str);
                    }
                }
                $.ajax({
                    url:root.inter.updateCategoryDiscountBelowCostPrice,
                    contentType: "application/json;charset=UTF-8",
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    data: JSON.stringify({
                        modifyPriceWay:modifyPriceWays,
                        categoryDiscount:inputmm,
                        contractCategoryDiscountId :contractCategoryDiscountIdarr,
                        skuCode:inputcode,
                        customerType:customertype

                    }),
                    success: function (data) {
                        console.log(data)
                        if(data.errorCode==0){
                            seahsdfs();
                           /* location.replace(location.href)*/
                        }else {

                            $.Huimodalalert(data.msg,2000);
                        }

                    },
                    error: function () {
                        $.Huimodalalert('失败！',2000);
                    }
                })
            }else {
                $.Huimodalalert(data.sub_msg,2000);
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })


    layer.close(index);
}
//单个删除
function detaildelete(id) {
    console.log(id);
    if(id==''){
        $.Huimodalalert('请选择批量选择数据！',2000);
        return false;
    }
    var objArr = [];
    if (id.indexOf(",") != -1) {
        var split = id.split(",");
        for (var i = 0; i < split.length; i++) {
            objArr.push(Number(split[i]));
        }
    } else {
        objArr.push(id);
    }

    console.log(JSON.stringify(objArr))
    $.ajax({
        url:root.inter.delBatchCategoryDiscountByList,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify(objArr),
        success: function (data) {
            if(data.errorCode==0){
                $.Huimodalalert('删除成功！',2000);
                $("#spu_all").attr("checked",false);
                seahsdfs();
            }else {
                $.Huimodalalert(data.msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
//批量删除
function deleteyy() {
    var spuIdArr=document.getElementsByName('spuId');
    var str=""
    for(var i=0; i < spuIdArr.length;i++){
        if(spuIdArr[i].checked==true){
            str+= spuIdArr[i].value+','
        }
    }
    str = str.substring(0, str.length - 1);
    detaildelete(str)

}
//查询结果页
function queryresults() {
    if($("#class1").val()==""&&$("#class2").val()==""&&$("#class3").val()==""&&$("#username").val().trim()==""&&$("#spuCode").val().trim()==""&&$("#Code").val().trim()==""&&$("#helpCode").val().trim()==""&&$("#spuName").val().trim()==""&&$("#skuName").val().trim()==""){
        $.Huimodalalert('请选择要查询的数据！',2000);
        return false;
    }


    $.ajax({
        url:root.inter.findContractCategoryDiscountByCondition,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify({
            "pageNum":1,
            "pageSize":20,
            "oneCategoryList":crmCustomerIdOnearry,
            "twoCategoryList":crmCustomerIdTwoarry,
            "threeCategoryList":crmCustomerIdThreearry,
            "brand":$("#username").val().trim(),
            "spuCode":$("#spuCode").val().trim(),
            "productName":$("#spuName").val().trim(),
            /*"skuCode":$("#skuCode").val().trim(),*/
            "helpCode":$("#helpCode").val().trim(),//助记码
            "productCode":$("#Code").val().trim(),
            "customerCode":getQueryString('customerCode'),
            "contractNum": getQueryString('contractNum'),
        }),
        success: function (result) {
            detaiist(result);
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.inter.findContractCategoryDiscountByCondition,
                        contentType: "application/json;charset=UTF-8",
                        ccache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":20,
                            "oneCategoryList":crmCustomerIdOnearry,
                            "twoCategoryList":crmCustomerIdTwoarry,
                            "threeCategoryList":crmCustomerIdThreearry,
                            "brand":$("#username").val().trim(),
                            "spuCode":$("#spuCode").val().trim(),
                            "productName":$("#spuName").val().trim(),
                            /*"skuCode":$("#skuCode").val().trim(),*/
                            "helpCode":$("#helpCode").val().trim(),//助记码
                            "productCode":$("#Code").val().trim(),
                            "customerCode":getQueryString('customerCode'),
                            "contractNum": getQueryString('contractNum'),
                        }),
                        success: function (result) {
                            detaiist(result);
                            $("#spu_all").attr("checked", false);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//搜索
function ditailquery(title,url) {
    if($("#spuCode").val().trim()!=""||$("#Code").val().trim()!=""||$("#helpCode").val().trim()!=""||$("#spuName").val().trim()!=""||$("#skuName").val().trim()!=""){
       /* sessionStorage.setItem("threeCategoryId",threeCategoryId);*/
        sessionStorage.setItem("brandid",jsonobj1);
        sessionStorage.setItem("spuCode",$("#spuCode").val().trim());
        sessionStorage.setItem("Code",$("#Code").val().trim());
        sessionStorage.setItem("helpCode",$("#helpCode").val().trim());
        sessionStorage.setItem("spuName",$("#spuName").val().trim());
        sessionStorage.setItem("skuName",$("#skuName").val().trim());

        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }else {
        $.Huimodalalert('请填写详细信息！',2000);
    }



}
//批量修改
function batchupdata() {
    var spuIdArr=document.getElementsByName('spuId');
    var str=""
    for(var i=0; i < spuIdArr.length;i++){
        if(spuIdArr[i].checked==true){
            str+= spuIdArr[i].value+','
        }
    }
    str = str.substring(0, str.length - 1);
    if(str==''){
        $.Huimodalalert('请勾选条目！',2000);
        return false;
    }
    var objArr = [];
    if (str.indexOf(",") != -1) {
        var split = str.split(",");
        for (var i = 0; i < split.length; i++) {
            objArr.push(Number(split[i]));
        }
    } else {
        objArr.push(str);
    }
    $.ajax({
        url:root.inter.checkCateDiscountByIds,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify(objArr),
        success: function (data) {
            $("#batchModification").modal("show")
            //数据清空
            if($("#adjustmentMethod").css("display")!="none"){
               $("#modifyPriceWay").val(10)
            }else {
               $("#modifyPriceWay2").val(10)
            }
            if($("#adjustmentMethod3").css("display")!="none"){
                $("#categoryDiscount").val("")
            }else {
               $("#categoryDiscount2").val("")
            }
            //展示
            if(data.msg=="true"){
                /*折扣率*/
                $("#adjustmentMethod2").css({
                    display: "block"
                });
                $("#adjustmentMethod3").css({
                    display: "block"
                });
                $("#adjustmentMethod").css({
                    display: "none"
                });
                $("#adjustmentMethod4").css({
                    display: "none"
                });

            }else {
                $("#adjustmentMethod2").css({
                    display: "none"
                });
                $("#adjustmentMethod3").css({
                    display: "block"
                });
                $("#adjustmentMethod").css({
                    display: "block"
                });
                $("#adjustmentMethod4").css({
                    display: "none"
                });
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
//取消
function close_model() {
    $("#batchModification").modal("hide");
}
//确定
function save_edit() {
    //id
    var spuIdArr=document.getElementsByName('spuId');
    var str=""
    for(var i=0; i < spuIdArr.length;i++){
        if(spuIdArr[i].checked==true){
            str+= spuIdArr[i].value+','
        }
    }
    str = str.substring(0, str.length - 1);
    var objArr = [];
    if (str.indexOf(",") != -1) {
        var split = str.split(",");
        for (var i = 0; i < split.length; i++) {
            objArr.push(Number(split[i]));
        }
    } else {
        objArr.push(str);
    }
    //
    var modifyPriceWayss=""
    if($("#adjustmentMethod").css("display")!="none"){
        modifyPriceWayss=$("#modifyPriceWay").val()
    }else {
        modifyPriceWayss=$("#modifyPriceWay2").val()
    }
    var categoryDiscount=""
    if($("#adjustmentMethod3").css("display")!="none"){
        if($("#categoryDiscount").val()==""){
            $.Huimodalalert("请填写百分比！",2000);
            return false;
        }
        categoryDiscount=$("#categoryDiscount").val()
    }else {
        if($("#categoryDiscount2").val()==""){
            $.Huimodalalert("请填写调节金额！",2000);
            return false;
        }
        if($("#categoryDiscount2").val()=="0"){
            $.Huimodalalert("调节金额不能输入0",2000);
            return false;
        }
        categoryDiscount=$("#categoryDiscount2").val()

    }
    if (customerTypes=="商店"){
        customertype=10
    }else {
        customertype=20
    }
    $.ajax({
        url:root.inter.updateBatchCategoryDiscountByList,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify({
            modifyPriceWay:modifyPriceWayss,
            categoryDiscount:categoryDiscount,
            contractCategoryDiscountId :objArr,
            customerType:customertype
        }),
        success: function (data) {

            if(data.errorCode==0){
                if(data.sub_code==2){
                    $("#batchModification").modal("hide");
                    inputmsg=data.sub_msg
                    modifyPriceWays=modifyPriceWayss
                    inputmm=categoryDiscount
                    updamm();
                }else if(data.sub_code==3){
                    $.Huimodalalert(data.sub_msg,2000);
                }else {
                    $.Huimodalalert('修改成功！',2000);
                    seahsdfs();
                    $("#batchModification").modal("hide");

                }
            }else {
                $.Huimodalalert(data.msg,2000);
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
//动态调用
function adjustmentMethod() {
    if($("#modifyPriceWay").val()==10){
        $("#adjustmentMethod3").css({
            display: "block"
        });
        $("#adjustmentMethod4").css({
            display: "none"
        });
    }else {
        $("#adjustmentMethod3").css({
            display: "none"
        });
        $("#adjustmentMethod4").css({
            display: "block"
        });
    }
}